package com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.authoritymanagement.core.domain.aggregatemodel.TermRelationshipGroupType;
import com.smedi.ismedi.authoritymanagement.core.domain.repository.TermRelationshipGroupRepository;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.model.TermRelationshipGroupEntity;
import com.smedi.ismedi.authoritymanagement.core.port.adapter.persistence.mybatis.mapper.TermRelationshipGroupMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
@AllArgsConstructor
public class TermRelationshipGroupRepositoryImpl extends ServiceImpl<TermRelationshipGroupMapper, TermRelationshipGroupEntity> implements TermRelationshipGroupRepository, IService<TermRelationshipGroupEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public TermRelationshipGroupType selectByTermRelationshipGroupTypeId(Long termRelationshipGroupTypeId) {
        TermRelationshipGroupEntity row = this.getBaseMapper().selectById(termRelationshipGroupTypeId);
        return dozerUtil.convertor(row, TermRelationshipGroupType.class);
    }

    @Override
    public TermRelationshipGroupType doInsert(TermRelationshipGroupType data) {
        TermRelationshipGroupEntity termRelationshipGroupEntity = dozerUtil.convertor(data, TermRelationshipGroupEntity.class);
        this.getBaseMapper().insert(termRelationshipGroupEntity);
        return dozerUtil.convertor(termRelationshipGroupEntity, TermRelationshipGroupType.class);
    }

    @Override
    public TermRelationshipGroupType doUpdate(TermRelationshipGroupType data) {
        TermRelationshipGroupEntity termRelationshipGroupEntity = dozerUtil.convertor(data, TermRelationshipGroupEntity.class);
        this.getBaseMapper().updateById(termRelationshipGroupEntity);
        return dozerUtil.convertor(termRelationshipGroupEntity, TermRelationshipGroupType.class);
    }

    @Override
    public void doDeleteByTermRelationshipGroupTypeId(Long termRelationshipGroupTypeId) {
        this.getBaseMapper().deleteById(termRelationshipGroupTypeId);
    }

    @Override
    public List<TermRelationshipGroupType> selectRolePermissionTypeList() {
        QueryWrapper<TermRelationshipGroupEntity> wrapper = new QueryWrapper();
        wrapper.orderByAsc("id");
        return dozerUtil.convertor(this.getBaseMapper().selectList(wrapper), TermRelationshipGroupType.class);
    }
}
